package com.ruibei.utils;

import java.util.Calendar;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;

import com.ruibei.R;

public class Utils {
	public  static void getDateTime(final TextView tv,Activity activity) {
		 AlertDialog.Builder builder = new AlertDialog.Builder(activity); 
        View view = View.inflate(activity, R.layout.date_time_dialog, null); 
        final DatePicker datePicker = (DatePicker) view.findViewById(R.id.date_picker); 
       // final TimePicker timePicker = (TimePicker) view.findViewById(R.id.time_picker); 
        builder.setView(view); 

        Calendar cal = Calendar.getInstance(); 
        cal.setTimeInMillis(System.currentTimeMillis()); 
        datePicker.init(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), null); 

//        timePicker.setIs24HourView(true); 
//        timePicker.setCurrentHour(cal.get(Calendar.HOUR_OF_DAY)); 
//        timePicker.setCurrentMinute(cal.get(Calendar.MINUTE)); 
               
            builder.setPositiveButton("确  定", new DialogInterface.OnClickListener() { 

                @Override 
                public void onClick(DialogInterface dialog, int which) { 

                    StringBuffer sb = new StringBuffer(); 
                    sb.append(String.format("%d-%02d-%02d",  
                            datePicker.getYear(),  
                            datePicker.getMonth() + 1, 
                            datePicker.getDayOfMonth())); 
//                    sb.append("  "); 
//                    sb.append(
//                    		String.format("%02d:%02d",timePicker.getCurrentHour(),timePicker.getCurrentMinute())
//                    		);

                    tv.setText(sb); 
                    dialog.cancel(); 
                } 
            }); 
            builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface arg0, int arg1) {
					arg0.cancel(); 
				}
			});
        Dialog dialog = builder.create(); 
        if(!dialog.isShowing()){
        	System.out.println("show 几次"); 
        	dialog.show(); 
	
        }
       
	}
}
